package com.student.service.impl;

import com.student.mapper.UserMapper;
import com.student.model.Room;
import com.student.model.User;
import com.student.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired//自动注入
    private UserMapper userMapper;

    @Override
    public User login(String name, String password){
        User user = userMapper.login(name,password);
        return user;
    }

    @Override
    public List<User> getAllUsers() {
        return userMapper.getAllUser();
    }

    @Override
    public int deleteUserById(Integer id) {
        int count = userMapper.deleteUserByld(id);
        return count;
    }

    @Override
    public int putUserInfo(User user) {
        int count = userMapper.putUserInfo(user);
        return count;
    }

    @Override
    public int insertBatchUser(List<User> users) {
        int count = 0;
        if(users != null && users.size() > 0){
            for(User user : users){
                if(user != null){
                    int c = userMapper.insertUser(user);
                    count += c;
                }
            }
        }
        return count;
    }

    @Override
    public int deleteBathUser(List<Integer> ids) {
        int count = 0;
        if(ids != null && ids.size() > 0){
            for(Integer id : ids){
                //查看是否有该房间
                User user = userMapper.getInforById(id);
                if(id != null){
                    int c = userMapper.deleteUserByld(id);
                    count += c;
                }
            }
        }
        return count;
    }
}
